USE SQLLib;
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID (N'tsql.fn_julian2gregorian') IS NOT NULL
BEGIN
   DROP FUNCTION tsql.fn_julian2gregorian;
	PRINT 'Previous version of fn_julian2gregorian dropped!'
END
GO

CREATE FUNCTION [tsql].[fn_julian2gregorian] ( @julian NUMERIC(5,0)) RETURNS DATETIME
  AS
	/*================================================================================================
	Name:			tsql.[fn_julian2gregorian]
	Type:			User defined function 
	Owner:					
	Description:	convert a gregorian date to julian date
	Parameters:		@gregorian = the date to convert
	Dependens on:  	[fn_julian2gregorian]
	Usage:			
					SELECT [tsql].[fn_julian2gregorian] (365)
	--------------------------------------------------------------------------------------------------
	Project:		http://sqllib.codeplex.com/
	Help:			
	Version:		201209026
	SrcCtrlApp:		SVN
	SrcCtrlPath:	http://sqllib.codeplex.com/SourceControl/list/changesets
	--------------------------------------------------------------------------------------------------
	History:		09/26/2012 - H.Winther - Function created
	================================================================================================*/  
	BEGIN
	  RETURN DATEADD (d, @julian, '1957-01-01');
	END
GO


